//node连接MySQL数据库
const mysql = require ('mysql')
//创建连接
let conn = mysql.createConnection({
    //主机地址
    host: 'localhost',
    //用户名
    user: 'root',
    //密码
    password: 'root',
    //数据库名称
    database: 'juzao',
    connectTimeout: 3306,  
    multipleStatements: true
})
  
module.exports = {
  query(sql){
    return new Promise(next =>{
      conn.connect()
      conn.query(sql, function (error, results, fields) {
        if (error) throw error;
        next(results)
        // conn.end()
      }) 
    })  
  }
}